/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-08-15
 * Time: 10:35
 */
public class Test {
    public static int removeDuplicates(int[] nums) {
        int n = nums.length;
        if (n == 0) {
            return 0;
        }
        int fast = 1;
        int slow = 1;
        while (fast < n) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;
    }
    public static void main(String[] args) {
        int[] nums = {1,1,2,3,4,6,6,8};
        int ret = removeDuplicates(nums);
        System.out.println(ret);
    }
    public static String truncateSentence(String s, int k) {
        StringBuffer stringBuffer = new StringBuffer();
        for (char a :s.toCharArray()) {
            if(a == ' ' && --k == 0){
                break;
            }else {
                stringBuffer.append(a);
            }
        }
        return stringBuffer.toString();
    }
    public static void main1(String[] args) {
/*        int x = 0;
        int y = 0;
        int k = 0;
        for (int z = 0; z < 5; z++) {
            if ((++x > 2) && (++y > 2) && (k++ > 2)){
                x++;
                ++y;
                k++;
            }
        }
        System.out.println(x + " " +y + " " +k);*/
/*        int a = 13;
        a  = a / 5;
        System.out.println(a);*/
        String str = "hello how are you contestant";
        String ret = truncateSentence(str,4);
        System.out.println(ret);
    }
}
